package com.yz.jdd.widget;

import android.os.CountDownTimer;
import android.widget.Button;

import java.lang.ref.WeakReference;

/**
 * Created by cc on 2017/2/20.
 */

public class TimeCounter extends CountDownTimer {

    private WeakReference<Button> weakButton;

    public TimeCounter(long millisInFuture, long countDownInterval, WeakReference<Button> weakButton) {
        super(millisInFuture, countDownInterval);
        this.weakButton = weakButton;
    }

    @Override
    public void onTick(long l) {
        if (weakButton.get() != null) {
            weakButton.get().setText(l / 1000 + "秒后重发");

            weakButton.get().setTextColor(0xff6c6e7a);
        }
    }

    @Override
    public void onFinish() {

        if (weakButton.get() != null) {
            weakButton.get().setEnabled(true);
            weakButton.get().setText("重发");
        }


    }
}
